<html>
    <head>
        <title>交易系统－－退票管理</title>
        <style type="text/css">
            <!--

            .style001 {
                font-size: 9px;
            }

            .STYLE4 {
                color: #7C99E2
            }

            .STYLE14 {
                color: #ddffff
            }

            .submitall {
                height: 22px;
                line-height: 22px;
            }
            -->
        </style>
    </head>
    <body>
        <div id="queryReturnedOrderGrid" class="x-form-item">
        </div>
        <script>
            var orderds;
            Ext.onReady(function(){
                //############## 订单Grid ##############
                var ordercm = new Ext.grid.ColumnModel([new Ext.grid.RowNumberer(), {
                        header: '编号',
                        dataIndex: 'id'
                    }, {
                        header: '乘机人',
                        dataIndex: 'pass',
                        width: 120
                    }, {
                        header: '定单号',
                        dataIndex: 'order_no',
                        width: 100
                    }, {
                        header: '航班号',
                        dataIndex: 'air_no',
                        width: 60
                    }, {
                        header: '始发地',
                        dataIndex: 'from',
                        width: 120
                    }, {
                        header: '目的地',
                        dataIndex: 'to',
                        width: 120
                    }, {
                        header: '乘机日期',
                        dataIndex: 'fly_date',
                        width: 70
                    }, {
                        header: '起飞时间',
                        dataIndex: 'fly_time',
                        width: 60
                    }, {
                        header: '预定时间',
                        dataIndex: 'created_at',
                        width: 120,
                        renderer: Ext.util.Format.dateRenderer('Y-m-d H:i:s')
                    }, {
                        header: '支付状态',
                        dataIndex: 'trx_status',
                        width: 70
                    }, {
                        header: '订单状态',
                        dataIndex: 'status',
                        width: 70
                    },{
                        header: '操作',
                        width: 130,
                        dataIndex: 'fromto',
                        renderer: operationRender
                    }]);
                function operationRender(value, cellmeta, record, rowIndex, columnIndex, store){
                    var content = "";
                    if (record.get("status")=="申请退票"){
                        content += "<a href=# onclick='drawWebOrder(\""+record.get("id")+"\")'>退票完成</a>";
                    }
                    return content
                }
                drawWebOrder = function(id){
                    Ext.Ajax.request({
                        url: '/ticket/draw_order',
                        params: 'id='+id+'&succ=true',
                        method: 'GET',
                        success: function(result, request){
                            if (result.responseText.indexOf("成功") >= 0) {
                                Ext.MessageBox.alert('操作成功', result.responseText);
                                orderds.reload();
                            }
                            else {
                                Ext.MessageBox.alert('操作失败', result.responseText);
                            }
                        },
                        failure: function(result, request){
                            Ext.MessageBox.alert('操作失败', '退票失败');
                        }
                    });
                }
                //隐藏order数据库id
                ordercm.setHidden(1, !ordercm.isHidden(1));
                orderds = new Ext.data.Store({
                    proxy: new Ext.data.HttpProxy({
                        url: '/ticket/getWebReturnedOrders'
                    }),
                    reader: new Ext.data.JsonReader({
                        totalProperty: 'totalProperty',
                        root: 'root'
                    }, [{
                            name: 'id'
                        }, {
                            name: 'pass'
                        }, {
                            name: 'order_no'
                        }, {
                            name: 'pnr'
                        }, {
                            name: 'trx_status'
                        }, {
                            name: 'status'
                        }, {
                            name: 'air_no'
                        },{
                            name: 'from',
                            mapping: 'from_airport.airport_name'
                        }, {
                            name: 'to',
                            mapping: 'to_airport.airport_name'
                        },{
                            name: 'fly_date'
                        }, {
                            name: 'fly_time'
                        }, {
                            name: 'created_at'
                        }])
                });

                var ordergridpanel = new Ext.grid.GridPanel({
                    el: 'queryReturnedOrderGrid',
                    ds: orderds,
                    cm: ordercm,
                    //sm: sm,
                    loadMask: true,
                    autoWidth: true,
                    collapsible: true,
                    animCollapse: true,
                    height: 380,
                    title: '订单信息',
                    bbar: new Ext.PagingToolbar({
                        pageSize: 10,
                        store: orderds,
                        displayInfo: true,
                        displayMsg: '显示第 {0} 条到 {1} 条记录，一共 {2} 条',
                        emptyMsg: "没有记录"
                    })

                });

                ordergridpanel.render();
                //ds.load();
                orderds.load({
                    params: {
                        start: 0,
                        limit: 10
                    }
                });

                //双击事件
                ordergridpanel.on('rowdblclick', function(ordergridpanel, rowIndex, e){
                    var srow = orderds.getById(orderds.data.items[rowIndex].id); //ds为绑定到grid的数据源
                    var weborder_id = srow.get("id");
                    //alert(weborder_id);
                    var url = "/ticket/viewOrder?id=" + weborder_id;
                    var tabs = Ext.getCmp('tabs');
                    tabs.add({
                        id: 'tab_view_order',
                        title: '查看订单',
                        //disabled: true,
                        autoLoad: {
                            url: url,
                            scripts: true
                        },
                        closable: true
                    }).show();

                });
            });
        </script>
    </body>
</html>
